package com.atguigu.spzx.common.exception;


import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.common.ResultCodeEnum;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {

    /**
     * 处理自定义异常
     *
     * @param exception {@link GuiguException}
     * @return {@link Result}
     */
    @ExceptionHandler(value = GuiguException.class)
    public Result guiguExceptionHandler(GuiguException exception) {
        exception.printStackTrace();
        return Result.build(null, exception.getResultCodeEnum());
    }

    /**
     * 处理系统异常
     *
     * @param exception {@link Exception}
     * @return {@link Result}
     */
    @ExceptionHandler(value = Exception.class)
    public Result systemExceptionHandler(Exception exception) {
        exception.printStackTrace();
        return Result.build(null, ResultCodeEnum.SYSTEM_ERROR);
    }


}
